package cn.wolfcode.wolf.article.controller;

import cn.wolfcode.wolf.article.domain.Destination;
import cn.wolfcode.wolf.article.qo.DestinationQuery;
import cn.wolfcode.wolf.article.service.DestinationService;
import cn.wolfcode.wolf.auth.anno.RequireLogin;
import cn.wolfcode.wolf.core.utils.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/destinations")
public class DestinationController {
    private final DestinationService destinationService;

    public DestinationController(DestinationService destinationService) {
        this.destinationService = destinationService;
    }

    @GetMapping
    public Result<Page<Destination>> pageList(DestinationQuery destinationQuery){
        return Result.success(destinationService.pageList(destinationQuery));
    }
    @GetMapping("/toasts")
    public Result<List<Destination>> toasts(Long destId){
        return Result.success(destinationService.findToasts(destId));
    }
    @GetMapping("/hotList")
    public Result<List<Destination>> hotList(Long rid){
        return Result.success(destinationService.findDestsByRid(rid));
    }

    @GetMapping("/list")
    public Result<List<Destination>> listAll(){
        return Result.success(destinationService.list());
    }

    @PostMapping("/save")
    public Result<?> save(Destination destination){
        destinationService.save(destination);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<?> updateById( Destination destination){
        destinationService.updateById(destination);
        return Result.success();
    }
    @PostMapping("/delete/{id}")
    public Result<?> deleteById(@PathVariable Long id){
        destinationService.removeById(id);
        return Result.success();
    }
    @GetMapping("/detail")
    public Result<Destination> getById(Long id){
        return Result.success(destinationService.getById(id));
    }
}

